Skip to content

Conversation

@realchonk
Copy link
Contributor

@realchonk realchonk commented Jan 29, 2025

Build Instructions

First build/get an arm-linux musl toolchain (like from https://toolchains.bootlin.com/, if you're on Linux).

export CC=/opt/armv7-eabihf--musl--stable-2024.05-1/bin/arm-buildroot-linux-musleabihf-gcc # for the bootlin toolchain
export RUSTC_VERSION=1.74.0 MRUSTC_TARGET_VER=1.74 MRUSTC_TARGET=arm-linux-musl

make RUSTCSTR # download rustc source
make -j16 # build mrustc
make -j16 LIBS # build minicargo and libstd

Building libcore fails

--- BUILDING core v0.0.0 (0.0% 1r,0w,18b,0c/19t)
> /home/benni/src/mrustc/bin/mrustc /home/benni/src/mrustc/rustc-1.74.0-src/library/core/src/lib.rs -o output-1.74.0-arm-linux-musl/libcore.rlib -C emit-depfile=output-1.74.0-arm-linux-musl/libcore.rlib.d --cfg
debug_assertions -O -L output-1.74.0-arm-linux-musl -L output-1.74.0-arm-linux-musl/host --crate-name core --crate-type rlib --crate-tag 0_0_0 --target arm-linux-musl -C emit-build-command=output-1.74.0-arm-linux-musl/libcore.rlib.sh --edition 2021 > output-1.74.0-arm-linux-musl/libcore.rlib_dbg.txt
 (0.0% 1r,0w,18b,0c/19t): core v0.0.0
MIR TODO: <*const u8 /*- <u8,>*/>::wrapping_offset BB0/TERM: Call intrinsic "arith_offset" - Call( retval = "arith_offset"::<T/*I:0*/,>( a0, a1, ), bb1, bb2)
Process was terminated with signal 6
FAILING COMMAND: /home/benni/src/mrustc/bin/mrustc /home/benni/src/mrustc/rustc-1.74.0-src/library/core/src/lib.rs -o output-1.74.0-arm-linux-musl/libcore.rlib -C emit-depfile=output-1.74.0-arm-linux-musl/libcore.rlib.d --cfg debug_assertions -O -L output-1.74.0-arm-linux-musl -L output-1.74.0-arm-linux-musl/host --crate-name core --crate-type rlib --crate-tag 0_0_0 --target arm-linux-musl -C emit-build-command=output-1.74.0-arm-linux-musl/libcore.rlib.sh --edition 2021
Env:  OUT_DIR=/home/benni/src/mrustc/output-1.74.0-arm-linux-musl/build_core CARGO_MANIFEST_DIR=/home/benni/src/mrustc/rustc-1.74.0-src/library/core CARGO_PKG_NAME=core CARGO_PKG_VERSION=0.0.0 CARGO_PKG_VERSION_MAJOR=0 CARGO_PKG_VERSION_MINOR=0 CARGO_PKG_VERSION_PATCH=0
 (5.3% 0r,0w,18b,1c/19t):
BUILD FAILED

TODO

@thepowersgang would you be able to help me with this?

@realchonk
Copy link
Contributor Author

Applying the following patch, leads to a different compiler error, not sure if they are related:

Patch

diff --git a/src/hir_conv/constant_evaluation.cpp b/src/hir_conv/constant_evaluation.cpp
index 88255837..80881eff 100644
--- a/src/hir_conv/constant_evaluation.cpp
+++ b/src/hir_conv/constant_evaluation.cpp
@@ -2879,7 +2879,7 @@ namespace HIR {
                     auto vr_dst = ValueRef(ptr_dst.second, ptr_dst.first - EncodedLiteral::PTR_BASE).slice(0, nbytes);
                     vr_dst.copy_from(state, vr_src);
                 }
-                else if( te->name == "offset" ) {
+                else if( te->name == "offset" || te->name == "arith_offset" ) {
                     auto ty = local_state.monomorph_expand(te->params.m_types.at(0).data().as_Pointer().inner);
                     size_t element_size;
                     if( !Target_GetSizeOf(state.sp, resolve, ty, element_size) )

Error

$ make LIBS
make -f minicargo.mk LIBS
make[1]: Entering directory '/home/benni/src/mrustc'
make -f Makefile all
make -C tools/minicargo/
make[2]: Entering directory '/home/benni/src/mrustc'
make[2]: Entering directory '/home/benni/src/mrustc/tools/minicargo'
make[2]: Nothing to be done for 'all'.
make[2]: Leaving directory '/home/benni/src/mrustc/tools/minicargo'
test -e bin/minicargo
make[2]: Nothing to be done for 'all'.
make[2]: Leaving directory '/home/benni/src/mrustc'
test -e bin/mrustc
bin/minicargo --vendor-dir rustc-1.74.0-src/vendor --script-overrides script-overrides/stable-1.74.0-linux/ --output-dir output-1.74.0-arm-linux-musl/ --target arm-linux-musl --manifest-overrides rustc-1.74.0-overrides.toml rustc-1.74.0-src/mrustc-stdlib/
warning: rustc-1.74.0-src/vendor/object/Cargo.toml:33: Unknown key `resolver` in [package]
warning: rustc-1.74.0-src/vendor/zeroize/Cargo.toml:42: Unknown key `resolver` in [package]
warning: rustc-1.74.0-src/vendor/derive_arbitrary/Cargo.toml:37: Unknown key `resolver` in [package]
warning: rustc-1.74.0-src/vendor/gimli/Cargo.toml:42: Unknown key `resolver` in [package]
--- BUILDING core v0.0.0 (0.0% 1r,0w,18b,0c/19t)
> /home/benni/src/mrustc/bin/mrustc /home/benni/src/mrustc/rustc-1.74.0-src/library/core/src/lib.rs -o output-1.74.0-arm-linux-musl/libcore.rlib -C emit-depfile=output-1.74.0-arm-linux-musl/libcore.rlib.d --cfg
debug_assertions -O -L output-1.74.0-arm-linux-musl -L output-1.74.0-arm-linux-musl/host --crate-name core --crate-type rlib --crate-tag 0_0_0 --target arm-linux-musl -C emit-build-command=output-1.74.0-arm-linux-musl/libcore.rlib.sh --edition 2021 > output-1.74.0-arm-linux-musl/libcore.rlib_dbg.txt
 (0.0% 1r,0w,18b,0c/19t): core v0.0.0
mrustc: src/hir/type.hpp:201: const HIR::TypeData::Data_Pointer& HIR::TypeData::as_Pointer() const: Assertion `m_tag == TAG_Pointer' failed.
Process was terminated with signal 6
FAILING COMMAND: /home/benni/src/mrustc/bin/mrustc /home/benni/src/mrustc/rustc-1.74.0-src/library/core/src/lib.rs -o output-1.74.0-arm-linux-musl/libcore.rlib -C emit-depfile=output-1.74.0-arm-linux-musl/libcore.rlib.d --cfg debug_assertions -O -L output-1.74.0-arm-linux-musl -L output-1.74.0-arm-linux-musl/host --crate-name core --crate-type rlib --crate-tag 0_0_0 --target arm-linux-musl -C emit-build-command=output-1.74.0-arm-linux-musl/libcore.rlib.sh --edition 2021
Env:  OUT_DIR=/home/benni/src/mrustc/output-1.74.0-arm-linux-musl/build_core CARGO_MANIFEST_DIR=/home/benni/src/mrustc/rustc-1.74.0-src/library/core CARGO_PKG_NAME=core CARGO_PKG_VERSION=0.0.0 CARGO_PKG_VERSION_MAJOR=0 CARGO_PKG_VERSION_MINOR=0 CARGO_PKG_VERSION_PATCH=0
 (5.3% 0r,0w,18b,1c/19t):
BUILD FAILED
make[1]: *** [minicargo.mk:236: LIBS] Error 1
make[1]: Leaving directory '/home/benni/src/mrustc'
make: *** [Makefile:158: LIBS] Error 2

@thepowersgang
Copy link
Owner

Run in a debugger to find out where that as_Pointer call is, it may be somewhere in constant evaluation.

@realchonk
Copy link
Contributor Author

realchonk commented Jan 29, 2025

The line if fails to compile is apprently this rustc-1.74.0-src/library/core/src/ascii/ascii_char.rs:587

const HEX_DIGITS: [AsciiChar; 16] = *b"0123456789abcdef".as_ascii().unwrap();

It doesn't make sense, because the exact same setup works for RISC-V and native, but not for ARM.
I think it's a different issue, but I can't figure out what it is.
Why would it try to constantly evaluate the arith_offset() intrinsic only on ARM?

For context: The arith_offset() intrinsic is used by std::ptr::wrapping_add(), which is used in is_ascii()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants